import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { forkJoin, Observable } from 'rxjs';
import { first, take } from 'rxjs/internal/operators';
import { Banner, HotTag, Singer, SongSheet } from 'src/app/service/data-types/common.types';
import { HomeService } from 'src/app/service/home.service';
import { SingerService } from 'src/app/service/singer.service';

type HomeDataType = [Banner[], HotTag[], SongSheet[], Singer[]]

@Injectable({ 
  providedIn: 'root' 
})

export class HomeResolveService implements Resolve<HomeDataType> {
  constructor(
    private homeService: HomeService,
    private singerService: SingerService
  ) { }

  resolve(): Observable<HomeDataType> {
    return forkJoin([
      this.homeService.getBanners(),
      this.homeService.getHotTags(),
      this.homeService.getPersonalSheetList(),
      this.singerService.getEnterSinger()
    ]).pipe(first());
  }
}

